/*#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;
void* threadrun1(void* args)
{
        while(1)
        {
            sleep(1);
        cout<<"我是线程1，我在运行。。。。"<<endl;
        }
}
void* threadrun2(void* args)
{
        while(1)
{
            sleep(1);
        cout<<"我是线程2，我在运行。。。。"<<endl;
}
}
void* threadrun3(void* args)
{
        while(1)
        {
            sleep(5);
        cout<<"我是线程3，我在运行。。。。"<<endl;
            char* str="hello";
            *str='H';
        }
}
int main()
{
    pthread_t t1,t2,t3;
    pthread_create(&t1,nullptr,threadrun1,nullptr);
    pthread_create(&t1,nullptr,threadrun2,nullptr);
    pthread_create(&t1,nullptr,threadrun3,nullptr);
    while(1)
    {
        sleep(1);
        cout<<"我是主线程，我在运行。。。。"<<endl;
    }










    return 0;
}*/

/*#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;
int g_val = 0; // 全局变量，在多线程场景中，我们多个线程看到的是同一个变量！ -- 为什么？

void *threadRun1(void *args)
{
    while (true)
    {
        sleep(1);
        cout << "t1 thread..." << getpid() << " &g_val: " << &g_val << " , g_val: " << g_val << endl;

    }
}

void *threadRun2(void *args)
{
    // char *s = "hello bit";
    int a=10;
    int* ptr=(int*)args;
    ptr=&a;
    while (true)
    {
        sleep(1);
        //cout << "t2 thread..." << getpid()  << " &g_val: " << &g_val << " , g_val: " << g_val++ << endl;
        // *s = 'H'; // 让这一个线程崩溃
    }
}

int main()
{
    pthread_t t1, t2, t3;
    int* ptr;
    //pthread_create(&t1, NULL, threadRun1, NULL);
    pthread_create(&t2, NULL, threadRun2,ptr);
    sleep(5);
    cout<<*ptr<<endl;
    while (true)
    {
        sleep(1);
        //cout << "main thread..." << getpid()  << " &g_val: " << &g_val << " , g_val: " << g_val << endl;
    }
}*/

/*#include <iostream>
#include <pthread.h>
using namespace std;
void* pthreadrun(void* arg)
{
    cout<<pthread_self()<<endl;;
}

int main()
{
    void* ret;
    pthread_t t;
    pthread_create(&t,NULL,pthreadrun,NULL);
    pthread_join(t,&ret);
    cout<<t<<endl;
    return 0;
}*/

#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;
void *pthreadrun(void *arg)
{
    while (1)
    {
        cout << "我是new线程" << endl;
        sleep(1);
    }
    
}
int main()
{
    pthread_t t;
    void* ret;
    pthread_create(&t, NULL, pthreadrun, NULL);
    sleep(5);
    pthread_cancel(t);
    pthread_join(t,&ret);
    cout<<(long)(ret)<<endl;

    return 0;
}